///////////////////////////////////////////////////////////////////////////////////////////////////
// Illusion Ray Development Kit (IDK)           Copyright (c) 2010 ( dimitriy.martynenko@gmail.com )
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-05-22
// Updated : ...
// Licence : NEW BSD
// Info	   : IDK Engine
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once

namespace Core
{
	struct TextureConfig
	{
		enum Enum
		{
			BaseMipLevel = 0,
		};
	};

	struct TextureCodec
	{
		enum Enum
		{
			DDS = 0,
			PVRTC,
			Value = PVRTC
		};

		inline static const pwchar Ext()
		{
			const pwchar Ext[] = 
			{
				".dds",
				".pvr"
			};
			return Ext[Value];
		}
	};


	/*-------------------------------------------------------------------------
	| TTextureMip:
	| ------------
	| TTextureMip
	---------------------------------------------------------------------------*/
	class TTextureMip : public TResource
	{
		typedef TResource Base;
	private:
		struct LoadProcess
		{
			enum Enum
			{
				None,
				ReadHeader,
				InitPixelData,
				ReadPixelData,
				Complete
			};
		};

		typedef DynamicArray<uint8> PixelData;
	private:
		uint mLevel;
		uint mWidth;
		uint mHeight;
		IDK::Pixel::Type::Enum mPixelType;
		PixelData mPixels;
		//for streaming
		uint mPixelDataReadInBytes;
		LoadProcess::Enum mLoadProcess;
	private:
		virtual bool OnTickLoad(void);
	public:
		virtual void Cleanup(void);
	public:
		TTextureMip(Threading::IThreadEvent& signal, ref<IDK::IStream> stream, IDK::Pixel::Type::Enum pixelType, uint priority, uint width, uint height);
	public:
		void SetLevel(uint level);
		uint GetLevel(void);
		uint GetWidth(void);
		uint GetHeight(void);
		PixelData GetData(void);
		uint GetSizeInBytes(void);
	};

	typedef ref<TTextureMip> TextureMip;


	//TODO: need divided on TBaseTexture, and TTexture::TBaseTexture - TRenderTarget using TBaseTexture for not duplicate code 
	class TTexture : public TArray<TextureMip>, virtual public IDK::ITexture
	{
        typedef TArray<TextureMip> Base;
		IDKClass;
	private:
		IDK::GPUTexture mTexture;
		uint mMipBind;
		String mPath;
		IDK::Pixel::Type::Enum mPixelType;
	protected:
		void BindGpuResource(IDK::IRenderState& rndState);
	public:
		TTexture(const String &path, IDK::Pixel::Type::Enum pixelType);
		String GetPath(void);
	public:
		virtual uint GetWidth(void);
		virtual uint GetHeight(void);
		virtual void SetPixelType(IDK::Pixel::Type::Enum fmt);
		virtual IDK::Pixel::Type::Enum GetPixelType(void);
		void AddMip(TextureMip mip);
		virtual uint GetMipCount(void);
		virtual IDK::Pixel::Filter::Enum GetFilter(void) const;
		virtual void BindTexture(IDK::IRenderState& rndState, uint index);
	};

	typedef ref<TTexture> Texture;
}
